/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * bocciawii
 * Copyright (C) Grupo de trabajo ULE 2010 <ulewii@googlegroups.com>
 * 
 * bocciawii is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * bocciawii is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "input.h"


/**
 * ESTO ESTÁ FUERA DE LA CLASE!
 */
wiimote** wiimotes;
int num_wiimotes = 0;
int done_poll_wm = 0;
int final_forever = 0;
float bateria = 1.0;

int frecuencia_status = 300000; // 5 minutos
int ultimo_status = 0;


void reset_botones(evento_wm* evento)
{
	for (int i = 0; i < 11; i++)
	{
		evento->just_pressed[i] = 0;
		evento->pressed[i] = 0;
		evento->just_released[i] = 0;
		evento->held[i] = 0;
	}
}

/*
 * Actualiza los datos del mando en un evento WM constantemente
 * Los acelerómetros se sobreescriben constantemente
 * Los botones sólo se escriben cuando se activan y quedan así hasta que 
 *  se hace un poll, momento en el que se resetean
 */
void actualizar_datos (evento_wm* evento, int i)
{

	evento->acel.raw_x = 0.0001 * round (wiimotes[i]->gforce.x * 10000.0);
	evento->acel.raw_y = 0.0001 * round (wiimotes[i]->gforce.y * 10000.0);
	evento->acel.raw_z = 0.0001 * round (wiimotes[i]->gforce.z * 10000.0);


	struct motion_plus_t* mp = (motion_plus_t*)&wiimotes[i]->exp.mp;
	evento->rot.raw_roll = mp->rx;
	evento->rot.raw_pitch = mp->rx;
	evento->rot.raw_yaw = mp->rx;

	evento->rotwm.raw_roll = wiimotes[i]->orient.roll;
	evento->rotwm.raw_pitch = wiimotes[i]->orient.pitch;
	evento->rotwm.raw_yaw = wiimotes[i]->orient.yaw;

	evento->pun.x = wiimotes[i]->ir.x;
	evento->pun.y = wiimotes[i]->ir.y;

	
	if (wiimotes[i]->ir.num_dots > 1)
		evento->pun.visible = 1;
	else 
		evento->pun.visible = 0;

	
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_ONE))
		evento->just_pressed[BOT_WM_UNO] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_TWO))
		evento->just_pressed[BOT_WM_DOS] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_A))
		evento->just_pressed[BOT_WM_A] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_B))
		evento->just_pressed[BOT_WM_B] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_PLUS))
		evento->just_pressed[BOT_WM_MAS] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_MINUS))
		evento->just_pressed[BOT_WM_MEN] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_UP))
		evento->just_pressed[BOT_WM_ARR] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_DOWN))
		evento->just_pressed[BOT_WM_ABA] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_LEFT))
		evento->just_pressed[BOT_WM_IZQ] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_RIGHT))
		evento->just_pressed[BOT_WM_DER] = 1;
	if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_HOME))
		evento->just_pressed[BOT_WM_HOME] = 1;


	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_ONE))
		evento->held[BOT_WM_UNO] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_TWO))
		evento->held[BOT_WM_DOS] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_A))
		evento->held[BOT_WM_A] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_B))
		evento->held[BOT_WM_B] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_PLUS))
		evento->held[BOT_WM_MAS] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_MINUS))
		evento->held[BOT_WM_MEN] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_UP))
		evento->held[BOT_WM_ARR] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_DOWN))
		evento->held[BOT_WM_ABA] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_LEFT))
		evento->held[BOT_WM_IZQ] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_RIGHT))
		evento->held[BOT_WM_DER] = 1;
	if (IS_HELD(wiimotes[i], WIIMOTE_BUTTON_HOME))
		evento->held[BOT_WM_HOME] = 1;

	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_ONE))
		evento->just_released[BOT_WM_UNO] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_TWO))
		evento->just_released[BOT_WM_DOS] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_A))
		evento->just_released[BOT_WM_A] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_B))
		evento->just_released[BOT_WM_B] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_PLUS))
		evento->just_released[BOT_WM_MAS] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_MINUS))
		evento->just_released[BOT_WM_MEN] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_UP))
		evento->just_released[BOT_WM_ARR] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_DOWN))
		evento->just_released[BOT_WM_ABA] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_LEFT))
		evento->just_released[BOT_WM_IZQ] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_RIGHT))
		evento->just_released[BOT_WM_DER] = 1;
	if (IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_HOME))
		evento->just_released[BOT_WM_HOME] = 1;

	for (int i = 0; i < 11; i++)
		evento->pressed[i] = evento->held[i] | evento->just_pressed[i];

}


void *th_wiimote(void *arg)
{

	
	while (!final_forever)
	{
	wiimotes = wiiuse_init(MAX_WIIMOTES);
	wiiuse_set_timeout(wiimotes, MAX_WIIMOTES, 10, 250);
	wiiuse_find(wiimotes,MAX_WIIMOTES, 5);
	
	num_wiimotes = wiiuse_connect(wiimotes, MAX_WIIMOTES);

	for (int i = 0; i < num_wiimotes; i++)
	{
		wiiuse_set_leds(wiimotes[i], WIIMOTE_LED_1);
		wiiuse_motion_sensing(wiimotes[i], 1);
		wiiuse_set_motion_plus(wiimotes[i], 1);
		
	}
	while (num_wiimotes)
	{
		evento_wm *evento = (evento_wm*) arg;
		done_poll_wm = 0;
		while (!done_poll_wm)
		{
			if (wiiuse_poll(wiimotes, num_wiimotes))
				
			for (int i = 0; i < num_wiimotes; i++)
			{
				switch (wiimotes[i]->event)
				{
					case WIIUSE_EVENT:
						actualizar_datos (evento, i);
						break;
				
					case WIIUSE_DISCONNECT:
					case WIIUSE_UNEXPECTED_DISCONNECT:
						done_poll_wm = 1;
						wiiuse_disconnect(wiimotes[i]);
						wiiuse_disconnected(wiimotes[i]);
						num_wiimotes --;
						break;

					case WIIUSE_STATUS:
						ultimo_status = SDL_GetTicks();
						bateria = wiimotes[i]->battery_level;
						break;
					case WIIUSE_READ_DATA:
						break;

					case WIIUSE_NUNCHUK_INSERTED:
						break;

					case WIIUSE_CLASSIC_CTRL_INSERTED:
						break;

					case WIIUSE_MOTION_PLUS_ACTIVATED:
						break;

					case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
						break;

					case WIIUSE_NUNCHUK_REMOVED:
					case WIIUSE_CLASSIC_CTRL_REMOVED:
					case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
					case WIIUSE_MOTION_PLUS_REMOVED:
						break;

					default:
						break;
				}// switch
				
				if (SDL_GetTicks() - ultimo_status > frecuencia_status)
					wiiuse_status(wiimotes[i]);
				
				if (bateria < .10)
				{
					wiiuse_disconnected(wiimotes[i]);
					wiiuse_disconnect(wiimotes[i]);
					done_poll_wm = 1;
					num_wiimotes --;
				}
			}// para todo wiimote
			
		} // done_poll
		
	} // num_wiimotes
	wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
} // final_forever
	pthread_exit(NULL);
}

/*
 * COMIENZA LA CLASE
 */
Input::Input(int x, int y)
{
	const float cuatrotercios = 4.0f/3.0f;
	const float dieciseisnueve = 16.0f/9.0f;
	
//	num_wiimotes = 0;
//	is_running = 0;
	nro_conex = 0;

	_paradaPoll = 0;
	_tiempoParadaPoll = 0;
	

	_vibrando = 0;
	
	ancho = x;
	alto = y;
	float res = (float)x/(float)y;

	float p43 = res - cuatrotercios > 0 ? 
					 res - cuatrotercios : 
					-res + cuatrotercios;
	float p169 = res - dieciseisnueve > 0 ? 
					 res - dieciseisnueve:
					-res + dieciseisnueve;
	
	if (p43 < p169)
		aspecto = WIIUSE_ASPECT_4_3;
	else
		aspecto = WIIUSE_ASPECT_16_9;

	posicion_barra = WIIUSE_IR_BELOW;


	evento = evento_cero ();

}

Input::~Input()
{
	if (_vibrando)
	{
			_vibrando = 0;
			wiiuse_rumble(wiimotes[0], 0);
	}
	
	done_poll_wm = 1;
	num_wiimotes = 0;
	final_forever = 1;
//	pthread_join(hilo, NULL);

	
}


void Input::Iniciar()
{
	wiimotes = wiiuse_init(MAX_WIIMOTES);
	wiiuse_set_timeout(wiimotes, MAX_WIIMOTES, 10, 250);
	pthread_create(&hilo, NULL, th_wiimote, &evento_WM);
	
}


void Input::Vibra(int duracion)
{
	if (num_wiimotes)
		if (!_vibrando)
		{
			_vibrando = 1;
			_comienzoVibracion = SDL_GetTicks();
			_tiempoVibracion = duracion;

			wiiuse_rumble(wiimotes[0], 1);
		}
}


void Input::SetIR(int activado)
{
	if (num_wiimotes)
	switch (activado)
	{
		case 1:
			PararPoll(1000);
			if (!WIIUSE_USING_IR(wiimotes[0]))
		{
					wiiuse_set_ir(wiimotes[0], 1);
			wiiuse_set_aspect_ratio(wiimotes[0], aspecto); 
			wiiuse_set_ir_position(wiimotes[0], posicion_barra); 
			wiiuse_set_ir_vres(wiimotes[0], ancho, alto); 
			wiiuse_set_ir_sensitivity(wiimotes[0], 5);
		}
			break;
		case 0:
			if (!WIIUSE_USING_IR(wiimotes[0]))
					wiiuse_set_ir(wiimotes[0], 0);
			break;
	}
}



accion_aplicacion Input::Poll(int estado)
{
	evento.id = ACC_NINGUNA;

	nro_conex = num_wiimotes;

	/*
	 *  Aquí quitaremos la vibración, es el único método que ya llamamos
	 *  La vibración, pues, siempre tendrá una duración mínima de un frame
	 *
	 */
	if (_vibrando)
		if (SDL_GetTicks()-_comienzoVibracion > _tiempoVibracion)
		{
			_vibrando = 0;
			wiiuse_rumble(wiimotes[0], 0);
		}
	
	if (done_poll_wm)
		if (SDL_GetTicks() - _paradaPoll > _tiempoParadaPoll)
		{
			done_poll_wm = 0;
			ReiniciarPoll ();
		}

			// Cogemos eventos

	if (SDL_PollEvent(&evento_SDL))
	{

		if ( evento_SDL.type == SDL_QUIT )
			evento.id = ACC_SALIR;

		//Pulsaciones puntuales
		if ( evento_SDL.type == SDL_KEYDOWN ) {
			evento.id = ACC_SELECCIONAR;
			// Dejemos que los del teclado siempre se pasen como SELECCIONAR
			// Y se filtren en partida.cc
			if (estado == EST_MENU)
				switch(evento_SDL.key.keysym.sym) {
/*					case SDLK_RETURN:
					case SDLK_UP:
					case SDLK_DOWN:
					case SDLK_LEFT:
					case SDLK_RIGHT: 
*/
					case SDLK_ESCAPE:
						evento.id_elemento = evento_SDL.key.keysym.sym;
						break;
				} // switch tipo tecla
/*
			if (estado == EST_PREPROCESO_LANZAMIENTO)
				switch(evento_SDL.key.keysym.sym) {
					case SDLK_F11:
						evento.id_elemento = evento_SDL.key.keysym.sym;
						break;
				} // switch tipo tecla

			if (estado & EST_INGAME)
				switch(evento_SDL.key.keysym.sym) {
					case SDLK_f:
					case SDLK_g:
					case SDLK_o:
					case SDLK_b:
					case SDLK_n:
					case SDLK_1:
					case SDLK_2:
					case SDLK_3:
					case SDLK_q:
					case SDLK_w:
					case SDLK_e:
					case SDLK_r:
					case SDLK_t:
					case SDLK_y:
					case SDLK_a:
					case SDLK_d:
					case SDLK_PLUS:
					case SDLK_MINUS:
					case SDLK_PAUSE:
					case SDLK_F10:
						evento.id_elemento = evento_SDL.key.keysym.sym;
						break;
				} // switch tipo tecla
			 
*/
		}// Key Down
/*
		if (estado & EST_MENU)
			if (evento_SDL.type == SDL_MOUSEBUTTONDOWN)
			{
				if (evento_SDL.button.button = SDL_BUTTON_LEFT)
				{
					evento.id = ACC_SELECCIONAR;
					evento.pun.visible = 1;
					evento.pun.x = evento_SDL.button.x;
					evento.pun.y = evento_SDL.button.y;
					evento.id_elemento = -1;

				}
			}
*/
	}// SDL_PollEvent



	// Partimos de la base de que se trata de un evento de SDL
	//	evento = evento_SDL;
	if (num_wiimotes)
	{
		// Y mezclamos con el del mote.
		// Aquí depuraríamos valores RAW en valores utilizables
		evento.acel.x = evento_WM.acel.raw_x;
		evento.acel.y = evento_WM.acel.raw_y;
		evento.acel.z = evento_WM.acel.raw_z;
		evento.rot.roll = evento_WM.rot.raw_roll;
		evento.rot.pitch = evento_WM.rot.raw_pitch;
		evento.rot.yaw = evento_WM.rot.raw_yaw;
		evento.rotwm.roll = evento_WM.rotwm.raw_roll;
		evento.rotwm.pitch = evento_WM.rotwm.raw_pitch;
		evento.rotwm.yaw = evento_WM.rotwm.raw_yaw;
		// Aquí obtendríamos las projected coordinates para el cursor
		// Nanai, de eso nada, vamos a "purificar" las coordenadas sobre las que se posa el wiimote
		if (evento_WM.pun.visible)
		{
			evento_WM.pun.x /= 40;
			evento_WM.pun.y /= 40;
			evento_WM.pun.x *= 40;
			evento_WM.pun.y *= 40;
		}

		switch (estado)
		{

			case EST_PREPROCESO_LANZAMIENTO:
				if (evento_WM.just_released[BOT_WM_B])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_F11;
				}
				break;







			// Estados IN_GAME
			case EST_JUEGO:
				if (evento_WM.just_pressed[BOT_WM_B])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_F10;
				}				

				if (evento_WM.just_pressed[BOT_WM_UNO])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_2;
				}
				if (evento_WM.just_pressed[BOT_WM_DOS])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_3;
				}

				if (evento_WM.just_pressed[BOT_WM_DOS])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_3;
				}

				if (evento_WM.just_pressed[BOT_WM_HOME])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_PAUSE;
				}



				if (evento_WM.pressed[BOT_WM_A] && evento_WM.pun.visible)
				{
					evento.id |= ACC_MIRAR;
					evento.pun = evento_WM.pun;
					SDL_WarpMouse(evento_WM.pun.x, evento_WM.pun.y);
					evento.des = InterpretarMirada();
				} 
				break;














			case EST_TACTICA:

				if (evento_WM.pressed[BOT_WM_MEN])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_MINUS;
				}
				if (evento_WM.pressed[BOT_WM_MAS])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_PLUS;
				}
				if (evento_WM.just_pressed[BOT_WM_B])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_1;
				}				
				if (evento_WM.just_pressed[BOT_WM_UNO])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_2;
				}
				if (evento_WM.just_pressed[BOT_WM_HOME])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_PAUSE;
				}


				if (evento_WM.pressed[BOT_WM_A] && evento_WM.pun.visible)
				{
					evento.id |= ACC_MIRAR;
					evento.pun = evento_WM.pun;
					SDL_WarpMouse(evento_WM.pun.x, evento_WM.pun.y);
					evento.des = InterpretarMirada();
				} 
				break;









			case EST_OBSERVACION:

				if (evento_WM.pressed[BOT_WM_MEN])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_MINUS;
				}
				if (evento_WM.pressed[BOT_WM_MAS])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_PLUS;
				}
				if (evento_WM.just_pressed[BOT_WM_B])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_1;
				}
				if (evento_WM.just_pressed[BOT_WM_DOS])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_3;
				}
				if (evento_WM.just_pressed[BOT_WM_HOME])
				{
					evento.id |= ACC_SELECCIONAR;
					evento.id_elemento = SDLK_PAUSE;
				}



				if (evento_WM.pressed[BOT_WM_A] && evento_WM.pun.visible)
				{
					evento.id |= ACC_MIRAR;
					evento.pun = evento_WM.pun;
					SDL_WarpMouse(evento_WM.pun.x, evento_WM.pun.y);
					evento.des = InterpretarMirada();
				} 
				break;














				// Estados TRANSICION
			case EST_ANIMACION:
				break;
			case EST_TRANSICION:
				break;

				// Estados MENU
			case EST_MENU:
				if (evento_WM.just_pressed[BOT_WM_DER])
				{
					evento.id = ACC_SELECCIONAR;
					evento.id_elemento = SDLK_RIGHT;
				}
				if (evento_WM.just_pressed[BOT_WM_IZQ])
				{
					evento.id = ACC_SELECCIONAR;
					evento.id_elemento = SDLK_LEFT;
				}
				if (evento_WM.just_pressed[BOT_WM_ARR])
				{
					evento.id = ACC_SELECCIONAR;
					evento.id_elemento = SDLK_UP;
				}
				if (evento_WM.just_pressed[BOT_WM_ABA])
				{
					evento.id = ACC_SELECCIONAR;
					evento.id_elemento = SDLK_DOWN;
				}
				if (evento_WM.just_pressed[BOT_WM_A])
				{
					evento.id = ACC_SELECCIONAR;
					evento.id_elemento = SDLK_RETURN;
				}


				break;
		}

	}








	// Devolvemos
	evento_previo = evento;
	evento = evento_cero();
	reset_botones (&evento_WM);
	return evento_previo;

}

desplazamiento Input::InterpretarMirada()
{
	cursor cur = evento.pun;

	int x = cur.x;
	int y = cur.y;
	int resx = ancho;
	int resy = alto;

	int eventoX = 0;
	int eventoY = 0;
	int factorX = 0;
	int factorY = 0;

	desplazamiento des;
	des.evento = 0;
	des.factor_x = 0;
	des.factor_y = 0;

	// Eje X
	if (x < (float(resx) * 0.1f)) {
		eventoX = O;
		factorX = 2;
	}
	else if (x < (float(resx) * 0.25f)) {
		eventoX = O;
		factorX = 1;
	}
	else if (x > resx * 0.9f) {
		eventoX = E;
		factorX = 2;
	}
	else if (x > resx * 0.75f) {
		eventoX = E;
		factorX = 1;
	}
	// Eje Y
	if (y < resy * 0.1f) {
		eventoY = N;
		factorY = 2;
	}
	else if (y < resy * 0.25f) {
		eventoY = N;
		factorY = 1;
	}
	else if (y > resy * 0.9f) {
		eventoY = S;
		factorY = 2;
	}
	else if (y > resy * 0.75f) {
		eventoY = S;
		factorY = 1;
	}

	des.evento = eventoX + eventoY;
	des.factor_x = factorX;
	des.factor_y = factorY;
	return des;
}

accion_aplicacion Input::evento_cero()
{
	accion_aplicacion e;
	cursor pun;
	resize_params res;
	rotacion rot;
	acel_vel acel;
	desplazamiento des;

	e.desde = ACC_NINGUNA;

	e.id = ACC_NINGUNA;
	e.id_elemento = 0;

	pun.x = 0;
	pun.y = 0;
	pun.visible = 0;

	res.width = 0;
	res.height = 0;

	rot.roll = 0;
	rot.pitch = 0;
	rot.yaw = 0;
	rot.raw_roll = 0;
	rot.raw_pitch = 0;
	rot.raw_yaw = 0;
	
	acel.x = 0;
	acel.y = 0;
	acel.z = 0;
	acel.raw_x = 0;
	acel.raw_y = 0;
	acel.raw_z = 0;

	des.evento = 0;
	des.factor_x = 0;
	des.factor_y = 0;

	e.pun = pun;
	e.res = res;
	e.rot = rot;
	e.acel = acel;
	e.vel = acel;
	
	return e;
	
}

void Input::evento_wm_cero(evento_wm* e)
{
	cursor pun;

	pun.x = 0;
	pun.y = 0;
	pun.visible = 0;

	e->pun = pun;
	
	
}


void Input::PararPoll(int duracion)
{
	done_poll_wm = 1;
	_tiempoParadaPoll = duracion;
	_paradaPoll = SDL_GetTicks();
}

void Input::ReiniciarPoll()
{
	done_poll_wm = 0;
}
